#!/usr/bin/env python
# -*- coding: utf-8 -*-
# datetime: 6/12/2023 下午9:46
# Author: name
# File: variable_model.py
# ide: PyCharm
# description: 全局变量相关数据库模型

from datetime import datetime
from typing import Union, List
from pydantic import BaseModel
from tortoise import fields
from tortoise.models import Model


class GlobalVariable(Model):
    id = fields.IntField(pk=True)
    name = fields.CharField(max_length=255)
    value = fields.TextField(max_length=20480)
    created_at = fields.CharField(max_length=255)
    updated_at = fields.CharField(max_length=255)

    class Meta:
        table = "global_variables"


class GlobalVariableIn(BaseModel):
    name: str
    value: Union[str, int, dict, List]


class GlobalVariableOut(BaseModel):
    id: int
    name: str
    value: Union[str, int, dict, List]
    created_at: str
    updated_at: str


# 定义用于包装分页查询结果的数据模型
class GlobalVariablePage(BaseModel):
    total: int
    page_size: int
    current_page: int
    search_key: str = None
    results: List[GlobalVariableOut]
